﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Net.Sockets;
using System.Net;
using System.Media;
using System.Reflection;
using System.IO;


namespace BAL
{
    public partial class SEOutStockDetail : Form
    {
        private LoginService.BarcodeJudgeServices bjs = new BAL.LoginService.BarcodeJudgeServices();
        Socket cliSocket = null;
        string ipAddr = "192.168.1.211";
        int port = 1024;

        private string FBillNo;
        private string FInterID;
        private string PkgsBarCode;
        private string PlaceBarCode;
        private string PlaceName;
        private string PkgsIsRegular;

        private string Fsku;
        private string StickLen;
        private string t_Stick;
        private string FQty;
        
        private int Total;
        private int ScanQty;
        private int LeftQty;
        private string ry;
        private string FSourceBillNo;
        private string Fdate;
        private string oldPkgsBarCode;  
        private string t_PlaceBarCode;
        private string t_PlaceName;
        private string t_Floor;
        private string t_FSku;
        private string t_StickLen;
        private string t_PkgsIsRegular;
        private string t_HelperCode;
        private string t_FQty;       

        private string DFInterID;
        private string DFEntryID;
        private string FDetailID;       
        private string FEntryID ;
        private string  HelperCode;
        private string ID;
        private int li_return = 0;
        private string Stratetype;
        //public SEOutStockDetail()
        //{
        //    InitializeComponent();
            
        //}
        public SEOutStockDetail(string fno, int num, string Fry, string fdate,string _ID,out int number)
        {
            InitializeComponent();
            FBillNo = fno;
            Total = num; // 总数量

            number = 0;
            DataSet ds = bjs.GetSEOutStockDetail(FBillNo,"");
            if (ds.Tables[0].Rows.Count > 0)
            {
                number = 1;
            }
            else { number = 0; }

            ry = Fry;
            Fdate = fdate;
            this.ID = _ID;
            this.tb_PkgsBarCode.Focus();
        }

        public void SetValue()
        {
            this.tb_PkgsBarCode.Text = "";
            this.tb_HelperCode.Text = "";
            this.tb_PlaceName.Text = "";
            this.tb_oldPkgsBarCode.Text = "";
            this.tb_PkgsBarCode.Focus();
        }

        private void SEOutStockDetail_Load(object sender, EventArgs e)
        {
            if (FBillNo == null || FBillNo == "")
            {
            }
            else
            {
                DataGridStyle();
                BindData();

                ScanQty = bjs.GetScanQty(FBillNo);
                LeftQty = Total - ScanQty;

                this.tb_FBillNo.Text = FBillNo.Trim();
                this.tb_Total.Text = Total.ToString();              
                this.tb_LeftQty.Text = LeftQty.ToString();
            }

        }

        //获取数据
        private void BindData()
        {
            DataSet ds = bjs.GetSEOutStockDetail(FBillNo,"");
            DataTable dt = new DataTable();
            dt = ds.Tables[0];
            //if (dt.Rows.Count <= 0)
            //{
            //    return;
            //}
            //else
            //{
            dataGrid1.DataSource = dt;
            
            //}
        }

        public void DataGridStyle()
        {
            DataGridTableStyle dts = new DataGridTableStyle();
            dataGrid1.TableStyles.Clear();
            dts.MappingName = "SEOutStockDetail";

            DataGridTextBoxColumn cl1 = new DataGridTextBoxColumn();
            cl1.HeaderText = "流水号";
            cl1.MappingName = "FInterID";
            cl1.Width = 0;
            dts.GridColumnStyles.Add(cl1);

            DataGridTextBoxColumn cl5 = new DataGridTextBoxColumn();
            cl5.HeaderText = "仓位名";
            cl5.MappingName = "PlaceName";
            cl5.Width = 62;
            dts.GridColumnStyles.Add(cl5);

            DataGridTextBoxColumn cl3 = new DataGridTextBoxColumn();
            cl3.HeaderText = "助记码";
            cl3.MappingName = "HelperCode";
            cl3.Width = 50;
            dts.GridColumnStyles.Add(cl3);          

            DataGridTextBoxColumn cl8 = new DataGridTextBoxColumn();
            cl8.HeaderText = "物料名";
            cl8.MappingName = "FItemName";
            cl8.Width = 110;
            dts.GridColumnStyles.Add(cl8);

            //DataGridTextBoxColumn cl12 = new DataGridTextBoxColumn();
            //cl12.HeaderText = "数量";
            //cl12.MappingName = "FQty";
            //cl12.Width = 40;
            //dts.GridColumnStyles.Add(cl12);

            DataGridTextBoxColumn cl11 = new DataGridTextBoxColumn();
            cl11.HeaderText = "根长";
            cl11.MappingName = "StickLen";
            cl11.Width = 40;
            dts.GridColumnStyles.Add(cl11);

            DataGridTextBoxColumn cl9 = new DataGridTextBoxColumn();
            cl9.HeaderText = "属性名";
            cl9.MappingName = "AttrValue";
            cl9.Width = 70;
            dts.GridColumnStyles.Add(cl9);

            DataGridTextBoxColumn cl2 = new DataGridTextBoxColumn();
            cl2.HeaderText = "包装码";
            cl2.MappingName = "PkgsBarCode";
            cl2.Width = 80;
            dts.GridColumnStyles.Add(cl2);

            DataGridTextBoxColumn cl7 = new DataGridTextBoxColumn();
            cl7.HeaderText = "Fsku";
            cl7.MappingName = "Fsku";
            cl7.Width = 150;
            dts.GridColumnStyles.Add(cl7);

            DataGridTextBoxColumn cl10 = new DataGridTextBoxColumn();
            cl10.HeaderText = "sxnum";
            cl10.MappingName = "sxnum";
            cl10.Width = 0;
            dts.GridColumnStyles.Add(cl10);

            
            //DataGridTextBoxColumn cl10 = new DataGridTextBoxColumn();
            //cl10.HeaderText = "类别";
            //cl10.MappingName = "PkgsIsRegular";
            //cl10.Width = 30;
            //dts.GridColumnStyles.Add(cl10);

            dataGrid1.TableStyles.Add(dts);
            
        }

        private void dataGrid1_CurrentCellChanged(object sender, EventArgs e)
        {
            DataGrid dataGrid1 = sender as DataGrid;
            int index = ((DataGrid)sender).CurrentCell.RowNumber;
            if (((DataTable)(dataGrid1.DataSource)).Rows.Count > 0)
            {
                ((DataGrid)sender).Select(index);
            }
            FSourceBillNo = ((DataTable)(dataGrid1.DataSource)).Rows[index]["FSourceBillNo"].ToString();
            FInterID = ((DataTable)(dataGrid1.DataSource)).Rows[index]["FInterID"].ToString();
            PlaceBarCode = ((DataTable)(dataGrid1.DataSource)).Rows[index]["PlaceBarCode"].ToString();
            PlaceName = ((DataTable)(dataGrid1.DataSource)).Rows[index]["PlaceName"].ToString();
            Fsku = ((DataTable)(dataGrid1.DataSource)).Rows[index]["Fsku"].ToString();

            oldPkgsBarCode = ((DataTable)(dataGrid1.DataSource)).Rows[index]["PkgsBarCode"].ToString();
            StickLen = ((DataTable)(dataGrid1.DataSource)).Rows[index]["StickLen"].ToString();
            FQty = ((DataTable)(dataGrid1.DataSource)).Rows[index]["FQty"].ToString();
            PkgsIsRegular = ((DataTable)(dataGrid1.DataSource)).Rows[index]["PkgsIsRegular"].ToString();

            DFInterID = ((DataTable)(dataGrid1.DataSource)).Rows[index]["DFInterID"].ToString();
            DFEntryID = ((DataTable)(dataGrid1.DataSource)).Rows[index]["DFEntryID"].ToString();
            FDetailID = ((DataTable)(dataGrid1.DataSource)).Rows[index]["FDetailID"].ToString();
            FBillNo  = ((DataTable)(dataGrid1.DataSource)).Rows[index]["FBillNo"].ToString();
            FEntryID = ((DataTable)(dataGrid1.DataSource)).Rows[index]["FEntryID"].ToString();
            HelperCode = ((DataTable)(dataGrid1.DataSource)).Rows[index]["HelperCode"].ToString();

            
            this.tb_FBillNo.Text = FBillNo.Trim();           
            this.tb_oldPkgsBarCode.Text = oldPkgsBarCode;           
            this.tb_PlaceName.Text = PlaceName;
            this.tb_PkgsBarCode.Focus();
            //this.tb_HelperCode.Text =  HelperCode.Trim();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            SEOutStock ics = new SEOutStock(this.ID);
            ics.Show();
            this.Hide();
        }
        
     
        private void tb_PkgsBarCode_KeyDown_1(object sender, KeyEventArgs e)
        {
            //if (e.KeyCode == Keys.Enter)
            //{

            //    PkgsBarCode = this.tb_PkgsBarCode.Text;

            //    if (PkgsBarCode == null || PkgsBarCode == "")
            //    {
            //        MessageBox.Show("请扫描包装码！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button3);
            //        return;
            //    }
            //    else
            //    {
            //        bool result = bjs.GetSEOutStockCode(PkgsBarCode, out  t_HelperCode, out  t_PlaceBarCode, out  t_PlaceName, out t_Floor, out  t_FSku, out  t_StickLen, out  t_Stick, out  t_FQty, out  t_PkgsIsRegular);
            //        if (result)
            //        {
            //            this.tb_PlaceName.Text = t_PlaceName;
            //            this.tb_HelperCode.Text = t_HelperCode;
            //            this.tb_PkgsBarCode.Text =PkgsBarCode;
            //            this.button1.Focus();
            //        }
            //        else
            //        {
            //            MessageBox.Show("没有该包装码！", "警告！", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button3);
            //            return;
            //        }
            //    }
            //}
        }

        private void tb_oldPkgsBarCode_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                oldPkgsBarCode = this.tb_oldPkgsBarCode.Text;
                if (oldPkgsBarCode == null || oldPkgsBarCode == "")
                {
                    MessageBox.Show("没有该包装码！", "警告！", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button3);
                    return;
                }
                else
                {
                    this.button2.Focus();
                }
            }
        }

        //li_return:1:根长、sku、定尺/不定尺、数量不匹配条件; 2;条码未在销售订单中，且已被锁库
        //3条码未在销售订单中但条码未被锁库 ;4出库成功；5扫描数量已达到发货数量;6出库失败;7插入成功；8插入失败；
        private void button1_Click(object sender, EventArgs e)
        {
            t_HelperCode = this.tb_HelperCode.Text.Trim();
            PkgsBarCode = this.tb_PkgsBarCode.Text.Trim();
            FBillNo = this.tb_FBillNo.Text;
            string plname = tb_PlaceName.Text.Trim();
            if (PkgsBarCode == null || PkgsBarCode == "")
            {
                MessageBox.Show("请扫描包装码！", "警告！", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button3);
                return;
            }

            li_return = bjs.UpdateSEOutStock(PkgsBarCode, FBillNo, t_HelperCode, t_FSku, t_StickLen, t_FQty, t_PkgsIsRegular, this.ID, plname);

            if (li_return == 1)
            {
                MessageBox.Show("根长、sku、定尺/不定尺、数量不匹配条件！", "警告！", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button3);
                SetValue();
               
                return;

            }
            else if (li_return == 2)
            {
                MessageBox.Show("包装码并不属于本出库单且已被其他单据锁库！", "警告！", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button3);
                SetValue();
               
                return;
            }
            else if (li_return == 3)
            {
                DialogResult dr = MessageBox.Show("包装码并不属于本出库单,请选择列表中的行进行替换", "提示信息", MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button3);
                if (dr == DialogResult.Yes)
                {
                    this.tb_oldPkgsBarCode.Focus();                   
                }
                else
                {
                    SetValue();
                    return;
                }

            }
            else if (li_return == 4) //成功
            {
                //语音读取成功
                string location = Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase.ToString());
                string path = location + "\\ysm.wav";
                SoundPlayer player = new SoundPlayer();
                player.SoundLocation = path;
                player.Load();
                player.Play();
                //刷新
                ScanQty = bjs.GetScanQty(FBillNo);
                LeftQty = Total - ScanQty;

                this.tb_LeftQty.Text = LeftQty.ToString();
                SetValue();

                DataGridStyle();
                BindData();
                

            }
            else if (li_return == 5)
            {
                MessageBox.Show("扫描数量已达到发货数量！", "警告！", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button3);
                SetValue();
                return;
            }
            else if (li_return == 67)
            {
                MessageBox.Show("此包装码已扫过,不能在进行扫描！", "警告！", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button3);
                SetValue();
                return;
            }
            else if (li_return == 6)
            {
                MessageBox.Show("出库失败！", "警告！", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button3);
                SetValue();
                return;
            }          
        }

        private void button2_Click(object sender, EventArgs e)
        {
            oldPkgsBarCode = this.tb_oldPkgsBarCode.Text;
            PkgsBarCode = this.tb_PkgsBarCode.Text;
            bool exist = false;
            bool getisstrate = false;

            if (oldPkgsBarCode == null || oldPkgsBarCode == "")
            {
                MessageBox.Show("原条码不能为空，请重新扫描", "警告！", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button3);
                this.tb_oldPkgsBarCode.Focus();
                return;
            }
            if (PkgsBarCode == null || PkgsBarCode == "")
            {
                MessageBox.Show("包装码不能为空，请重新扫描", "警告！", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button3);
                this.tb_PkgsBarCode.Focus();
                return;
            }
            if (PkgsBarCode == oldPkgsBarCode )
            {
                MessageBox.Show("包装码与原条码相同", "警告！", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button3);
                this.tb_PkgsBarCode.Focus();
                return;
            }
            exist = bjs.ISExist(PkgsBarCode, oldPkgsBarCode, FBillNo);
           
            if (exist == true)
            {
                MessageBox.Show("包装码与原条码属于同一个销售出库单，不能相互替换，应选择“提交”按钮", "警告！", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button3);
                this.tb_PkgsBarCode.Focus();
                return;
            }
            //查询要替换的信息是否是正常数据
            getisstrate = bjs.GetStkis(PkgsBarCode, out Stratetype);
            if (getisstrate ==true)
            {
                if (Stratetype !="0")
                {
                    MessageBox.Show("请扫描状态为正常的货物进行替换！", "警告！", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button3);
                    this.tb_PkgsBarCode.Focus();
                    return;
                }

            }
            //查询有没有该包装条码
            bool resultg = bjs.GetSEOutStockCode(PkgsBarCode, out  t_HelperCode, out  t_PlaceBarCode, out  t_PlaceName, out t_Floor, out  t_FSku, out  t_StickLen, out  t_Stick, out  t_FQty, out  t_PkgsIsRegular);
            if (resultg)
            {
                this.tb_PlaceName.Text = t_PlaceName;
                this.tb_HelperCode.Text = t_HelperCode;
                this.tb_PkgsBarCode.Text = PkgsBarCode;
            }
            else
            {
                MessageBox.Show("没有该包装码！", "警告！", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button3);
                return;
            }
            if (Fsku == null || Fsku == "" || StickLen == null || StickLen == "" || FQty == null || FQty == "" || PkgsIsRegular == null || PkgsIsRegular == "")
            {
                MessageBox.Show("sku、根长、数量、规格为空，不合要求，请重新扫描", "警告！", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button3);
                this.tb_PkgsBarCode.Focus();
                return;
            }
            else
            {
                if (!t_HelperCode.Substring(0, 1).Equals(HelperCode.Substring(0, 1)))
                {
                    if (t_HelperCode.Substring(0, 1) == "A")
                    {
                        MessageBox.Show("此包装码是定尺不能替换！", "警告！", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button3);
                        return;
                    }
                    else
                    {
                        MessageBox.Show("此包装码是不定尺不能替换！", "警告！", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button3);
                        return;
                    }
                }
                else
                {
                    if (PkgsIsRegular == "1")
                    {
                        if (Fsku == t_FSku && StickLen == t_StickLen && FQty == t_FQty && PkgsIsRegular == t_PkgsIsRegular)
                        {

                            int ls_return1 = bjs.InsertSEOutStock(PkgsBarCode, oldPkgsBarCode, DFInterID, DFEntryID, FDetailID, FBillNo, FEntryID, FSourceBillNo, ry, t_HelperCode, t_PkgsIsRegular, this.ID);
                            if (ls_return1 > 0)
                            {
                                li_return = 7;
                                MessageBox.Show("替换成功", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button3);

                                ScanQty = bjs.GetScanQty(FBillNo);
                                LeftQty = Total - ScanQty;

                                this.tb_LeftQty.Text = LeftQty.ToString();
                                SetValue();
                                DataGridStyle();
                                BindData();
                            }
                            else if (ls_return1 == 0)
                            {
                                li_return = 8;
                                MessageBox.Show("替换失败！", "警告！", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button3);
                                SetValue();
                                return;
                            }
                        }
                        else
                        {
                            li_return = 9;
                            MessageBox.Show("替换失败！,sku、根长、数量、规格不匹配", "警告！", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button3);
                            SetValue();
                            return;
                        }
                    }
                    else if (PkgsIsRegular == "2")
                    {
                        if (Fsku == t_FSku && FQty == t_FQty && PkgsIsRegular == t_PkgsIsRegular)
                        {
                            int ls_return1 = bjs.InsertSEOutStock(PkgsBarCode, oldPkgsBarCode, DFInterID, DFEntryID, FDetailID, FBillNo, FEntryID, FSourceBillNo, ry, t_HelperCode, t_PkgsIsRegular, this.ID);
                            if (ls_return1 > 0)
                            {
                                li_return = 7;
                                MessageBox.Show("替换成功", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button3);

                                ScanQty = bjs.GetScanQty(FBillNo);
                                LeftQty = Total - ScanQty;

                                this.tb_LeftQty.Text = LeftQty.ToString();
                                SetValue();
                                DataGridStyle();
                                BindData();
                            }
                            else if (ls_return1 == 0)
                            {
                                li_return = 8;
                                MessageBox.Show("替换失败！", "警告！", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button3);
                                SetValue();
                                return;
                            }
                        }
                        else
                        {
                            li_return = 9;
                            MessageBox.Show("替换失败！,sku、根长、数量、规格不匹配", "警告！", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button3);
                            SetValue();
                            return;
                        }
                    }
                }
            }
        }

        private void button4_Click(object sender, EventArgs e)
        {
            oldPkgsBarCode = this.tb_oldPkgsBarCode.Text;
            if (oldPkgsBarCode == null || oldPkgsBarCode == "")
            {
                MessageBox.Show("原条码不能为空，请选择列表中的某条记录", "警告！", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button3);
                return;
            }

            DialogResult dr = MessageBox.Show("包装码" + oldPkgsBarCode + "确实消件吗?", "提示信息", MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button3);
            if (dr == DialogResult.Yes)
            {

                int ls_return2 = bjs.UpdateNotFindCode(oldPkgsBarCode, FBillNo, Program.user);
                if (ls_return2 > 0)
                {
                    li_return = 9;
                    MessageBox.Show("确实未找到包装码！", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button3);
                   
                    ScanQty = bjs.GetScanQty(FBillNo);
                    LeftQty = Total - ScanQty;
                    this.tb_LeftQty.Text = LeftQty.ToString();
                    this.tb_PkgsBarCode.Text = "";
                    this.tb_PlaceName.Text = "";
                    this.tb_oldPkgsBarCode.Text = "";
                    this.tb_HelperCode.Text = "";
                    this.tb_PkgsBarCode.Focus();
                    DataGridStyle();
                    BindData();
                }
                else
                {
                    MessageBox.Show("包装码不在本出库单！", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button3);
                    return;
                }
            }
        }

        private void tb_PkgsBarCode_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {

                PkgsBarCode = this.tb_PkgsBarCode.Text;

                if (PkgsBarCode == null || PkgsBarCode == "")
                {
                    MessageBox.Show("请扫描包装码！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button3);
                    return;
                }
                else
                {

                    bool result = bjs.GetSEOutStockCode(PkgsBarCode, out  t_HelperCode, out  t_PlaceBarCode, out  t_PlaceName, out t_Floor, out  t_FSku, out  t_StickLen, out  t_Stick, out  t_FQty, out  t_PkgsIsRegular);
                    if (result)
                    {
                        this.tb_PlaceName.Text = t_PlaceName;
                        this.tb_HelperCode.Text = t_HelperCode;
                        this.tb_PkgsBarCode.Text = PkgsBarCode;
                        this.button1.Focus();
                    }
                    else
                    {
                        MessageBox.Show("没有该包装码！", "警告！", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button3);
                        return;
                    }
                }
            }
        }
        /// <summary>
        /// 消件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button5_Click(object sender, EventArgs e)
        {
            oldPkgsBarCode = this.tb_oldPkgsBarCode.Text;
            if (oldPkgsBarCode == null || oldPkgsBarCode == "")
            {
                MessageBox.Show("原条码不能为空，请选择列表中的某条记录", "警告！", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button3);
                return;
            }

            DialogResult dr = MessageBox.Show("包装码" + oldPkgsBarCode + "确实要退件吗?", "提示信息", MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button3);
            if (dr == DialogResult.Yes)
            {

                int ls_return2 = bjs.UpdateTUIFindCode(oldPkgsBarCode, FBillNo, Program.user);
                if (ls_return2 > 0)
                {
                    li_return = 9;
                    MessageBox.Show("确实要退件包装码！", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button3);

                    ScanQty = bjs.GetScanQty(FBillNo);
                    LeftQty = Total - ScanQty;
                    this.tb_LeftQty.Text = LeftQty.ToString();
                    this.tb_PkgsBarCode.Text = "";
                    this.tb_PlaceName.Text = "";
                    this.tb_HelperCode.Text = "";
                    this.tb_oldPkgsBarCode.Text = "";
                    this.tb_PkgsBarCode.Focus();
                    DataGridStyle();
                    BindData();
                }
                else
                {
                    MessageBox.Show("包装码不在本出库单！", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button3);
                    return;
                }
            }
        }
        //排序lina20190813
        private void PXBTN_Click(object sender, EventArgs e)
        {

            PkgsBarCode = this.tb_PkgsBarCode.Text;

            if (PkgsBarCode == null || PkgsBarCode == "")
            {
                MessageBox.Show("请扫描包装码！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button3);
                return;
            }
            else
            {
                //查询有没有该包装条码
                bool resultg = bjs.GetSEOutStockCode(PkgsBarCode, out  t_HelperCode, out  t_PlaceBarCode, out  t_PlaceName, out t_Floor, out  t_FSku, out  t_StickLen, out  t_Stick, out  t_FQty, out  t_PkgsIsRegular);
                if (resultg ==false)
                {
                    MessageBox.Show("没有该包装码！", "警告！", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button3);
                    return;
                }
                DialogResult dr = MessageBox.Show("包装码" + oldPkgsBarCode + "确实排后吗?", "提示信息", MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button3);
                if (dr == DialogResult.Yes)
                {
                    PkgsBarCode = this.tb_PkgsBarCode.Text.Trim();
                    FBillNo = this.tb_FBillNo.Text;
                    int num = bjs.Updatepx(PkgsBarCode, FBillNo);
                    if (num > 0)
                    {
                        ScanQty = bjs.GetScanQty(FBillNo);
                        LeftQty = Total - ScanQty;
                        this.tb_LeftQty.Text = LeftQty.ToString();
                        SetValue();
                        DataGridStyle();
                        BindData();
                    }
                    else
                    {
                        MessageBox.Show("排后功能更新失败，请联系开发人员查找原因！", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button3);
                        return;
                    }
                }
            }

        }
        /// <summary>
        /// 单击复选框时发生事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void checkBox1_Click(object sender, EventArgs e)
        {
            if (checkBox1.Checked)
            {
                DataGridStyle();
                DataSet ds = bjs.GetSEOutStockDetail(FBillNo, "181");
                DataTable dt = new DataTable();
                dt = ds.Tables[0];
                //if (dt.Rows.Count <= 0)
                //{
                //    return;
                //}
                //else
                //{
                dataGrid1.DataSource = dt;
            }
            else
            {
                DataGridStyle();
                BindData();
            }
           
        }

       

    
    }
}